package com.crm.manager.controller;

import com.crm.common.core.domain.R;
import com.crm.manager.domain.dto.ActivityStatisticsListDTO;
import com.crm.manager.domain.dto.TimeDto;
import com.crm.manager.domain.vo.EChartsVO;
import com.crm.manager.domain.vo.PageVO;
import com.crm.manager.domain.vo.VulnerabilityMapVO;
import com.crm.manager.result.PageResult;
import com.crm.manager.service.Report2Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/report")
public class Report2Controller {
    @Autowired
    private Report2Service report2Service;

    @GetMapping("/getVulnerabilityMap/{begin}/{end}")
    public R<VulnerabilityMapVO> getVulnerabilityMap(
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        return R.ok(report2Service.getVulnerabilityMap(begin, end));
    }

    @GetMapping("/salesStatistics/{begin}/{end}")
    public EChartsVO salesStatistics(
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        return report2Service.salesStatistics(begin, end);
    }
    @GetMapping("/deptStatisticsList/{begin}/{end}")
    public PageVO deptStatisticsList(
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end, TimeDto dto){
        return report2Service.deptStatisticsList(begin, end, dto);
    }

    @GetMapping("/chanelStatistics/{begin}/{end}")
    public R<List<Map>> chanelStatistics(
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        return R.ok(report2Service.chanelStatistics(begin, end));
    }
    @GetMapping("/activityStatistics/{begin}/{end}")
    public R<List<Map>> activityStatistics(
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        return R.ok(report2Service.activityStatistics(begin, end));
    }
    @GetMapping("/activityStatisticsList")
    public PageVO activityStatisticsList(ActivityStatisticsListDTO dto){
        return report2Service.activityStatisticsList(dto);
    }
}
